package Pre.treeMap;

import java.util.Objects;
import java.util.TreeMap;

public class TreeMapTest {
    public static void main(String[] args) {
        TreeMap<Integer, String> treeMap = new TreeMap<>();
        treeMap.put(1, "迪丽热巴");
        treeMap.put(4, "灰太狼");
        treeMap.put(3, "喜羊羊");
        treeMap.put(2, "黑猫警长");
        System.out.println(treeMap);
        System.out.println(treeMap.firstEntry().getKey()); // 获取第一个键值对
        System.out.println(treeMap.lastEntry().getValue()); // 最后一个键值对
        System.out.println(treeMap.firstKey()); // 第一个键
        System.out.println(treeMap.lastKey()); // 最后一个键
        System.out.println(treeMap.floorEntry(1)); // 小于等于key的最大值
        System.out.println(treeMap.lowerEntry(1)); // 小于key的最大值
        System.out.println(treeMap.ceilingEntry(1)); // 大于等于key的最小值
        System.out.println(treeMap.higherEntry(1)); // 大于key的最小值
        System.out.println(treeMap.headMap(3)); // 小于key的所有集合
        System.out.println(treeMap.headMap(3, true)); // 小于等于key的所有集合
        System.out.println(treeMap.tailMap(3)); // 大于等于key的所有集合
        System.out.println(treeMap.tailMap(3, false)); // 大于key的所有集合
        System.out.println(treeMap.pollFirstEntry()); // 1
        System.out.println(treeMap.pollLastEntry()); // 4
    }
}
class Emp{
    private static int idindex = 1;
    private int id;
    private String mame;
    private String Address;

    public Emp(int id, String mame, String address) {
        this.id = idindex ++ ;
        this.mame = mame;
        Address = address;
    }

    public int getId() {
        return id;
    }

    public String getMame() {
        return mame;
    }

    public String getAddress() {
        return Address;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Emp emp = (Emp) o;
        return id == emp.id && Objects.equals(mame, emp.mame) && Objects.equals(Address, emp.Address);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, mame, Address);
    }

    @Override
    public String toString() {
        return "Emp{" +
                "id=" + id +
                ", mame='" + mame + '\'' +
                ", Address='" + Address + '\'' +
                '}';
    }
}